// pages/rentIncome/rentIncome.js 
const app = getApp()
const util = require('../../utils/util.js')
const lbbService = require('../service/service.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabNum: 0,
    equipTab:1,
    toView:'mId'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    that.setData({
      hospitalId: options.hospitalId,
      scrollHeight: app.getScrollHeight(55)
    })
    that.getList()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  toggleEquip: function (e) {
    console.log('>>', e)
    this.setData({
      equipTab: e.currentTarget.dataset.activeNum
    })
  },
  toggleTab: function(e) {
    console.log('>>', e)
    this.setData({
      tabNum: e.currentTarget.dataset.index
    })
  },
  getList: function(){
    let that = this
    let letter = '/'
    let nowTime = new Date()
    let endTime = util.formatTime(nowTime).replace(/letter/g, "-")
    console.log('endTime', endTime)
    let eightAgo = Date.parse(nowTime) - 1000 * 60 * 60 * 24 * 30 * 8
    let startTime = util.formatTime(new Date(eightAgo)).replace(/letter/g, "-").substr(0, 7)
    lbbService.getUseRecord({
      hospitalId: parseInt(that.data.hospitalId),
      startTime: startTime,
      endTime: endTime},function(res){
        that.setId(res.data)
        that.setData({
          tabNum: res.data.length - 1
        })
      })
  },
  setId: function (rentStatic){
    let that = this
    console.log(rentStatic)
    for(let i=0;i<rentStatic.length;i++){
      rentStatic[i].mId = "mId" + i
    }
    that.setData({
      rentStatic: rentStatic,
      toView: "mId" + JSON.stringify(rentStatic.length - 1)
    })
  }
})